<!DOCTYPE HTML>
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description("Receive fragmented WebSocket frames.");

window.jsTestIsAsync = true;

var url = "ws://localhost:8880/fragmented-frames";
var ws = new WebSocket(url);
var closeEvent;
var expectedMessages = ["First message", "Second message", "Third message"];
var actualMessages = [];

ws.onopen = function()
{
    debug("onopen() was called.");
};

ws.onmessage = function(event)
{
    var message = event.data;
    debug("onmessage() was called. (message = \"" + message + "\")");
    actualMessages.push(message);

    if (actualMessages.length == 3)
        ws.close();
};

ws.onclose = function(event)
{
    closeEvent = event;
    shouldBeTrue("closeEvent.wasClean");
    shouldBeTrue("actualMessages.length === expectedMessages.length");
    for (var i = 0; i < expectedMessages.length; ++i)
        shouldBeEqualToString("actualMessages[" + i + "]", expectedMessages[i]);
    finishJSTest();
};

</script>
</body>
</html>
